/**
 * Created by sunga on 2019/1/2.
 */

$().ready(function () {

    $("#optimizationss,#optimizationsss").change(function () {
        if ($("#optimizationss").val() == 1 || $("#optimizationsss").val() == 1) {
            $("#option_detail,#option_details").attr("readonly", "readonly").val("-Xms512m -Xmx512m -XX:PermSize=256M -XX:MaxPermSize=256M -Ddruid.registerToSysProperty=true -Dfile.encoding=utf-8").css("color", "red");
        } else {
            $("#option_detail,#option_details").val("").attr("placeholder", "调优参数详情").removeAttr("readonly").css("color", "");
        }
    });
    $("#interface_typess").change(function () {
        if ($("#add-checkbox-http").is(':checked') == true) {
            $("#http-port-path").css("display", "block");
            console.log(1111123333);
        } else {
            $("#http-port-path").css("display", "none");
        }
    });
        $("#interface_typesss").change(function () {
        if ($("#edit-checkbox-https").is(':checked') == true) {
            $("#http-port-paths").css("display", "block");
            console.log(1111122222);
        } else {
            $("#http-port-paths").css("display", "none");
        }
    });
    $("#copy_appinfo").click(function () {
        var all_apps = new Array();
        $('[data-app-idss="application-app"]').each(function () {
            if ($(this).is(':checked') == true) {
                all_apps.push($(this).attr("data-appss-id"));
            }
        });
        if(all_apps.length == 0){
            swal({
                title: "<small>必须选择应用信息!</small>",
                html: true
                });
        }else {
            $('#copy_info').modal({backdrop: 'static', keyboard: false});
            $.ajax({
            url:"/serviceinfo/envinfo/",
            type: "get",
            success:function (data) {
                data = JSON.parse(data);
                var hh = "";
                $("#groupss option").remove();
                $.each(data["group_list"], function (index, value) {
                    hh += '<option value="' + value[0] + '"> ' + value[1] + '</option>'
                });
                $("#groupss").append(hh);

                var gg = "";
                $("#env_typeff option").remove();
                $.each(data["env_list"], function (index, value) {
                    gg += '<option value="' + value[0] + '"> ' + value[1] + '</option>';
                });
                $("#env_typeff").append(gg);
            }
        })
        }
    });

    $("#copy_save_app").click(function () {
        var all_apps = new Array();
        $('[data-app-idss="application-app"]').each(function () {
            if ($(this).is(':checked') == true) {
                all_apps.push($(this).attr("data-appss-id"));
            }
        });
        all_ids = JSON.stringify(all_apps);
        env_id = $("#env_typeff").val();
        group = $("#groupss").val();
        $.ajax({
            url: "/serviceinfo/copy_appinfo/",
            type: "post",
            data:{"env_id":env_id,"group":group,"app_ids":all_ids},
            success:function (data) {
                var data = JSON.parse(data);
                $('#copy_info').modal("hide");
                if (data["status"] == 200) {
                        // window.location.href = '/serviceinfo/';
                        swal({
                            title: "",
                            text: "项目创建成功"
                        }, function () {
                            // window.location.href = '/service/connservice_list/?env_type='+ +'&search_app='+ ;
                            window.location.href = '/serviceinfo/';
                        })
                    } else if (data["status"] == 500) {
                        swal({
                            title: "",
                            text: "项目已存在"
                        });
                    }
            }
        })
    });

        $("#add_envinfo").click(function () {
        $('#env_info').modal({backdrop: 'static', keyboard: false});
    });

    $("#env_save_info").click(function () {
        var env_name = $("#env_name").val();

        $.ajax({
            url: "/serviceinfo/add_env/",
            type: "post",
            data:{"env_name":env_name},
            success:function (data) {
                var data = JSON.parse(data);
                console.log(data, typeof data);
                $('#add_envinfo').modal("hide");
                if (data["status"] == 200) {
                        // window.location.href = '/serviceinfo/';
                        swal({
                            title: "",
                            text: "环境添加成功"
                        }, function () {
                            // window.location.href = '/service/connservice_list/?env_type='+ +'&search_app='+ ;
                            window.location.href = '/serviceinfo/';
                        })
                    } else if (data["status"] == 500) {
                        swal({
                            title: "",
                            text: "该环境已存在"
                        });
                        console.log("eeeeeeee");
                    }
            }
        })
    })

    $("#configcenter_addr").change(function () {
        if ($("#configcenter_addr").val() != '') {
            $("#configcenter_addr").css("border-color", "");
        }
    });
    //添加应用信息
    $("#add_serviceinfo").click(function () {
        // $('#url_info').modal('show');
        $('#url_info').modal({backdrop: 'static', keyboard: false});
        $("#app_type").removeAttr("readonly");
        $("#proname").removeAttr("readonly");
        var oprate_id = $("#add_serviceinfo").attr("ser-oprate");
        $.ajax({
            url: "/serviceinfo/appinfo/",
            type: "get",
            success: function (data) {
                var data = JSON.parse(data);
                console.log(data, typeof data);

                // app_type
                var hh = "";
                $("#app_type option").remove();
                $.each(data["app_type"], function (index, value) {
                    hh += '<option value="' + value[0] + '"> ' + value[1] + '</option>'
                });
                $("#app_type").append(hh);

                //调优参数
                var bb = "";
                $("#optimizationss option").remove();
                $.each(data["option_typess"], function (index, value) {
                    bb += '<option value="' + value[0] + '"> ' + value[1] + '</option>'
                });
                $("#optimizationss").append(bb);

                // 调优参数详情
                if ($("#optimizationss").val() == 1) {
                    $("#option_detail").attr("readonly", "readonly").val("-Xms512m -Xmx512m -XX:PermSize=256M -XX:MaxPermSize=256M -Ddruid.registerToSysProperty=true -Dfile.encoding=utf-8").css("color", "red");
                } else {
                    $("#option_detail").val(data["optimization_detail"]);
                }

                // 操作系统版本
                var yy = "";
                $("#system_version option").remove();
                $.each(data["system_releasess"], function (index, value) {
                    yy += '<option value="' + value[0] + '"> ' + value[1] + '</option>'
                });
                $("#system_version").append(yy);

                // Java版本
                var xx = "";
                $("#java_version option").remove();
                $.each(data["java_versionss"], function (index, value) {
                    xx += '<option value="' + value[0] + '"> ' + value[1] + '</option>'
                });
                $("#java_version").append(xx);

                // CPU 容量
                var zz = "";
                $("#cpu_capacity option").remove();
                $.each(data["cpu_capacityss"], function (index, value) {
                    zz += '<option value="' + value[0] + '"> ' + value[1] + '</option>'
                });
                $("#cpu_capacity").append(zz);

                // 内存容量
                var ww = "";
                $("#mem_capacity option").remove();
                $.each(data["mem_capacityss"], function (index, value) {
                    ww += '<option value="' + value[0] + '"> ' + value[1] + '</option>'
                });
                $("#mem_capacity").append(ww);

                // 配置中心类型
                var cc = "";
                $("#configcenterss option").remove();
                $.each(data["configcenter_typess"], function (index, value) {
                    cc += '<option value="' + value[0] + '"> ' + value[1] + '</option>'
                });
                $("#configcenterss").append(cc);

                $("#interface_typess label").remove();
                var ee = '<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_type" id="add-checkbox-http" value="http"><span class="form-check-sign">http</span></label>&nbsp;&nbsp;&nbsp;&nbsp;';
                var ff = '<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_type" id="checkbox-dubbo" value="dubbo"><span class="form-check-sign">dubbo</span></label>';
                console.log(ee);
                console.log(ff);
                gg = ee + ff;
                $("#interface_typess").append(gg);
            }
        });

    });

    $(".editproj").click(function () {
        // $('#url_info').modal('show');
        $('#edit_info').modal({backdrop: 'static', keyboard: false});
        console.log($(this));
        var proj_id = $(this).attr('data-proj-id');
        // var env_type = $(this).attr('data-env-id');
        console.log(proj_id);
        $.ajax({
            url: "/serviceinfo/appinfo/",
            type: "post",
            data: {"proj_id": proj_id},
            success: function (data) {
                var data = JSON.parse(data);
                console.log(data, typeof data);
                // 确定这是修改的保存时，使用
                $("#proj_iddd").val('');
                $("#proj_iddd").val(data["proj_id"]);

                $("#pronames").val('');
                $("#pronames").val(data["proname"]);

                $("#gitaddrs").val('');
                $("#gitaddrs").val(data["gitaddr"]);

                $("#git_releases").val('');
                $("#git_releases").val(data["git_releases"]);

                $("#obj-nums").val();
                $("#obj-nums").val(data["node_num"]);

                // 确定环境类型
                $("#app_type option").remove();
                var aa = "";
                $("#env_typesss option").remove();
                $.each(data["env_typess"], function (index, value) {
                    console.log(index);
                    console.log(value);
                    if (data["git_env"] == value[0]) {
                        aa += '<option value="' + value[0] + '">' + value[1] + '</option>'
                    }
                });
                $("#env_typesss").attr("readonly", "readonly").append(aa);

                // 确定应用类型
                $("#app_types").attr("readonly", "readonly").append('<option value="' + data["app_type"] + '" selected="selected"> ' + data["app_type"] + '</option>');

                // 操作系统版本
                var mm = "";
                $("#system_versionsss option").remove();
                $.each(data["system_releasess"], function (index, value) {
                    console.log(index);
                    console.log(value);
                    if (data["system_release"] == value[0]) {
                        mm += '<option value="' + value[0] + '" selected="selected"> ' + value[1] + '</option>'
                    } else {
                        mm += '<option value="' + value[0] + '">' + value[1] + '</option>'
                    }
                });
                $("#system_versionsss").append(mm);

                // 确定Java版本
                var nn = "";
                $("#java_versions option").remove();
                $.each(data["java_versionss"], function (index, value) {
                    console.log(index);
                    console.log(value);
                    if (data["java_version"] == value[0]) {
                        nn += '<option value="' + value[0] + '" selected="selected"> ' + value[1] + '</option>'
                    } else {
                        nn += '<option value="' + value[0] + '">' + value[1] + '</option>'
                    }
                });
                $("#java_versions").append(nn);

                // CPU
                var pp = "";
                $("#cpu_capacitys option").remove();
                $.each(data["cpuss"], function (index, value) {
                    console.log(index);
                    console.log(value);
                    if (data["cpu"] == value[0]) {
                        pp += '<option value="' + value[0] + '" selected="selected"> ' + value[1] + '</option>'
                    } else {
                        pp += '<option value="' + value[0] + '">' + value[1] + '</option>'
                    }
                });
                $("#cpu_capacitys").append(pp);

                // mem
                var rr = "";
                $("#mem_capacitys option").remove();
                $.each(data["memss"], function (index, value) {
                    console.log(index);
                    console.log(value);
                    if (data["mem"] == value[0]) {
                        rr += '<option value="' + value[0] + '" selected="selected"> ' + value[1] + '</option>'
                    } else {
                        rr += '<option value="' + value[0] + '">' + value[1] + '</option>'
                    }
                });
                $("#mem_capacitys").append(rr);

                // 调优参数详情
                $("#option_details").val('');
                $("#option_details").val(data["optimization"]);

                // 调优参数类型
                var bb = "";
                $("#optimizationsss option").remove();
                $.each(data["option_typess"], function (index, value) {
                    if (data["optimization"] == value[0]) {
                        bb += '<option value="' + value[0] + '" selected="selected"> ' + value[1] + '</option>'
                    } else {
                        bb += '<option value="' + value[0] + '">' + value[1] + '</option>'
                    }
                });
                $("#optimizationsss").append(bb);
                if (data["optimization"] == 1) {
                    $("#option_details").attr("readonly", "readonly").val("-Xms512m -Xmx512m -XX:PermSize=256M -XX:MaxPermSize=256M -Ddruid.registerToSysProperty=true -Dfile.encoding=utf-8").css("color", "red");
                } else {
                    $("#option_details").val(data["optimization_detail"]);
                }

                // 配置中心类型
                var cc = "";
                $("#configcentersss option").remove();
                $.each(data["configcenter_typess"], function (index, value) {
                    if (data["configcenter"] == value[0]) {
                        cc += '<option value="' + value[0] + '" selected="selected"> ' + value[1] + '</option>'
                    } else {
                        cc += '<option value="' + value[0] + '">' + value[1] + '</option>'
                    }
                });
                $("#configcentersss").append(cc);
                $("#configcenter_addrs").val(data["configcenter_addr"]);
                var interss = data["interface_typess"];

                $("#interface_typesss label").remove();
                // $("#interface_typesss").html("接口:&nbsp;&nbsp;&nbsp;&nbsp;");
                var ttinterss = JSON.parse(data["interface_type"]);
                console.log(ttinterss);
                console.log(typeof ttinterss);

                if (ttinterss.length == 0) {
                    var ee = '&nbsp;&nbsp;&nbsp;&nbsp;<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_types" id="edit-checkbox-https" value="http"><span class="form-check-sign">http</span></label>&nbsp;&nbsp;&nbsp;&nbsp;';
                    var ff = '<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_types" id="checkbox-dubbo" value="dubbo"><span class="form-check-sign">dubbo</span></label>';

                } else {
                        // $("#app-ports").val('');
                        // $("#app-paths").val('');
                        // $("#service-paths").val('');
                        // $("#hostnames").val('');
                        // $("#http-port-paths").css("display", "none");
                    if (ttinterss.indexOf("http") != -1 && ttinterss.indexOf("dubbo") == -1) {
                        console.log("http,edit!!!");
                        var ee = '&nbsp;&nbsp;&nbsp;&nbsp;<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_types" id="edit-checkbox-https" value="http" checked="checked"><span class="form-check-sign">http</span></label>&nbsp;&nbsp;&nbsp;&nbsp;';
                        var ff = '<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_types" id="checkbox-dubbo" value="dubbo"><span class="form-check-sign">dubbo</span></label>';
                        // $("#http-port-paths").css("display", "block");
                        // $("#app-ports").val(data["port"]);
                        // $("#app-paths").val(data["request_path"]);
                        // $("#service-paths").val(data["service_path"]);
                        // $("#hostnames").val(data["hostname"]);
                        console.log("eidt1111")
                    } else if (ttinterss.indexOf("dubbo") != -1 && ttinterss.indexOf("http") == -1) {

                        var ee = '&nbsp;&nbsp;&nbsp;&nbsp;<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_types" id="edit-checkbox-https" value="http"><span class="form-check-sign">http</span></label>&nbsp;&nbsp;&nbsp;&nbsp;';
                        var ff = '<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_types" id="checkbox-dubbo" value="dubbo" checked="checked"><span class="form-check-sign">dubbo</span></label>';
                        console.log(333333);
                    } else if (ttinterss.indexOf("dubbo") != -1 && ttinterss.indexOf("http") != -1) {

                        var ee = '&nbsp;&nbsp;&nbsp;&nbsp;<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_types" id="edit-checkbox-https" value="http" checked="checked"><span class="form-check-sign">http</span></label>&nbsp;&nbsp;&nbsp;&nbsp;';
                        var ff = '<label class="form-check-label"><input class="form-check-input" type="checkbox" name="interface_types" id="checkbox-dubbo" value="dubbo" checked="checked"><span class="form-check-sign">dubbo</span></label>';
                        console.log(55555);
                        // $("#http-port-paths").css("display", "block");
                        // $("#app-ports").val(data["port"]);
                        // $("#app-paths").val(data["request_path"]);
                        // $("#service-paths").val(data["service_path"]);
                        // $("#hostnames").val(data["hostname"]);
                    }
                }
                gg = ee + ff;
                $("#interface_typesss").append(gg);
            }
        })
    });

    $("#add_save_app").click(function () {
        console.log("bbbbcuuu");
        var proname = $("#proname").val();
        var app_type = $("#app_type").val();
        var gitaddr = $("#gitaddr").val();
        var git_releases = $("#git_release").val();
        var obj_num = $("#obj-num").val();
        var optimization = $("#optimizationss").val();
        var optimization_detail = $("#option_detail").val();
        var system_version = $("#system_version").val();
        var java_version = $("#java_version").val();
        var cpu_capacity = $("#cpu_capacity").val();
        var mem_capacity = $("#mem_capacity").val();
        var configcenter = $("#configcenterss").val();
        var configcenter_addr = $("#configcenter_addr").val();
        var interface_type = new Array();
        $('[name="interface_type"]').each(function (i, e) {
            console.log($(this).is(':checked'));
            if ($(this).is(':checked') == true) {
                console.log(e);
                interface_type.push(e.value);
            }
        });
        // var port = $("#app-port").val();
        // var app_path = $("#app-path").val();
        // var service_path = $("#service-path").val();
        // var hostname = $("#hostname").val();

        console.log(proname);
        console.log(app_type);
        console.log(gitaddr);
        console.log(git_releases);
        console.log(optimization);
        console.log(optimization_detail);
        console.log(system_version);
        console.log(java_version);
        console.log(cpu_capacity);
        console.log(mem_capacity);
        console.log(configcenter);
        console.log(configcenter_addr);
        console.log(interface_type);
        // console.log(port);
        // console.log(app_path);
        // console.log(service_path);
        // console.log(hostname);
        if (
            proname == "" ||
            gitaddr == "" ||
            configcenter_addr == "" ||
            git_releases == ""
        ) {
            swal({
                title: "<small>必填字段有为空</small>!",
                text: "<span style='color:#FF0000'>应用名称|GIT地址|GIT分支|配置中心地址不能为空<span>",
                html: true
            });
            if (
                proname == "" && gitaddr == "" && configcenter_addr == "" && git_releases == ""
            ) {
                $("#proname").css("border-color", "red");
                $("#gitaddr").css("border-color", "red");
                $("#configcenter_addr").css("border-color", "red");
                $("#git_release").css("border-color", "red");
            } else if (
                git_releases == "" && proname == "" && gitaddr == "" && configcenter_addr != ""
            ) {
                $("#proname").css("border-color", "red");
                $("#gitaddr").css("border-color", "red");
                $("#git_release").css("border-color", "red");
            } else if (
                git_releases == "" && proname == "" && gitaddr != "" && configcenter_addr == ""
            ) {
                $("#proname").css("border-color", "red");
                $("#configcenter_addr").css("border-color", "red");
                $("#git_release").css("border-color", "red");
            } else if (
                git_releases == "" && proname != "" && gitaddr == "" && configcenter_addr == ""
            ) {
                $("#gitaddr").css("border-color", "red");
                $("#configcenter_addr").css("border-color", "red");
                $("#git_release").css("border-color", "red");
            }else if (
                git_releases != "" && proname == "" && gitaddr == "" && configcenter_addr == ""
            ) {
                $("#gitaddr").css("border-color", "red");
                $("#configcenter_addr").css("border-color", "red");
                $("#proname").css("border-color", "red");
            } else if (
                git_releases == "" && proname != "" && gitaddr != "" && configcenter_addr == ""
            ) {
                $("#configcenter_addr").css("border-color", "red");
                $("#git_release").css("border-color", "red");
            } else if (
                git_releases == "" && proname != "" && gitaddr == "" && configcenter_addr != ""
            ) {
                $("#gitaddr").css("border-color", "red");
                $("#git_release").css("border-color", "red");
            } else if (
                git_releases == "" && proname == "" && gitaddr != "" && configcenter_addr != ""
            ) {
                $("#proname").css("border-color", "red");
                $("#git_release").css("border-color", "red");
            }else if (
                git_releases != "" && proname != "" && gitaddr != "" && configcenter_addr == ""
            ) {
                $("#proname").css("border-color", "red");
                $("#configcenter_addr").css("border-color", "red");
            }else if (
                git_releases != "" && proname != "" && gitaddr == "" && configcenter_addr != ""
            ) {
                $("#gitaddr").css("border-color", "red");
            }else if (
                git_releases == "" && proname != "" && gitaddr != "" && configcenter_addr != ""
            ) {
                $("#git_release").css("border-color", "red");
            }else if (
                git_releases != "" && proname == "" && gitaddr != "" && configcenter_addr != ""
            ) {
                $("#proname").css("border-color", "red");
            }
        } else {
            $("#add_save_app").modal("hide");
            $.ajax({
                url: "/serviceinfo/add/",
                type: "post",
                data: {
                    "proname": proname,
                    "app_type": app_type,
                    "gitaddr": gitaddr,
                    "git_releases": git_releases,
                    "obj_num": obj_num,
                    // "hostname":hostname,
                    // "port":port,
                    // "app_path":app_path,
                    // "service_path":service_path,
                    "optimization": optimization,
                    "optimization_detail": optimization_detail,
                    "system_version": system_version,
                    "java_version": java_version,
                    "cpu_capacity": cpu_capacity,
                    "mem_capacity": mem_capacity,
                    "configcenter": configcenter,
                    "configcenter_addr": configcenter_addr,
                    "interface_type": JSON.stringify(interface_type)
                },
                success: function (data) {
                    var data = JSON.parse(data);
                    console.log(data);
                    if (data["status"] == 200) {
                        // window.location.href = '/serviceinfo/';
                        swal({
                            title: "",
                            text: "应用创建成功"
                        }, function () {
                            // window.location.href = '/service/connservice_list/?env_type='+ +'&search_app='+ ;
                            window.location.href = '/serviceinfo/';
                        })
                    } else if (data["status"] == 500) {
                        swal({
                            title: "",
                            text: "应用已存在"
                        });
                        console.log("eeeeeeee");
                    }
                }
            })
        }
    });

    $("#edit_save_app").click(function () {
        var linkss = $(".active a").attr("href");
        var app_id = $("#proj_iddd").val();
        var gitaddr = $("#gitaddrs").val();
        var git_releases = $("#git_releases").val();
        var obj_num = $("#obj-nums").val();
        // var hostname = $("#hostnames").val();
        var optimization = $("#optimizationsss").val();
        var optimization_detail = $("#option_details").val();
        var system_version = $("#system_versionsss").val();
        var java_version = $("#java_versions").val();
        var cpu_capacity = $("#cpu_capacitys").val();
        var mem_capacity = $("#mem_capacitys").val();
        var configcenter = $("#configcentersss").val();
        var configcenter_addr = $("#configcenter_addrs").val();

        var interface_type = new Array();
        $('[name="interface_types"]').each(function (i, e) {
            console.log(i);
            console.log(e);
            console.log($(this).is(':checked'));
            if ($(this).is(':checked') == true) {
                console.log(e);
                interface_type.push(e.value);
            }
        });
        // var port = $("#app-ports").val();
        // var request_path = $("#app-paths").val();
        // var service_path = $("#service-paths").val();

        console.log(app_id);
        console.log(gitaddr);
        console.log(git_releases);
        console.log(optimization);
        console.log(optimization_detail);
        console.log(system_version);
        console.log(java_version);
        console.log(cpu_capacity);
        console.log(mem_capacity);
        console.log(configcenter);
        console.log(configcenter_addr);
        console.log(interface_type);
        // console.log(port);
        // console.log(request_path);
        // console.log(service_path);

        $.ajax({
            url: "/serviceinfo/edit/" + app_id + "/",
            type: "post",
            data: {
                "app_id": app_id,
                "gitaddr": gitaddr,
                "git_releases": git_releases,
                "obj_num": obj_num,
                // "hostname":hostname,
                "optimization": optimization,
                "optimization_detail": optimization_detail,
                "system_version": system_version,
                "java_version": java_version,
                "cpu_capacity": cpu_capacity,
                "mem_capacity": mem_capacity,
                "configcenter": configcenter,
                "configcenter_addr": configcenter_addr,
                "interface_type": JSON.stringify(interface_type)
                // "port": port,
                // "request_path": request_path,
                // "service_path": service_path
            },
            success: function (data) {
                var data = JSON.parse(data);
                console.log(data);
                if (data["status"] == 200) {
                    // window.location.href = '/serviceinfo/';
                    swal({
                        title: "",
                        text: "项目修改成功"
                    }, function () {
                        // window.location.href = '/service/connservice_list/?env_type='+ +'&search_app='+ ;
                        window.location.href = linkss;
                    })
                } else if (data["status"] == 500) {
                    swal({
                        title: "",
                        text: "项目修改失败"
                    },function () {
                        // window.location.href = '/service/connservice_list/?env_type='+ +'&search_app='+ ;
                        window.location.href = linkss;
                    });
                    console.log("eeeeeeee");
                }
            }
        })
    });

    $(".deleteproj").click(function () {
        var linkss = $(".active a").attr("href");
        var proj_id = $(this).attr('data-proj-id');
        var group = $("#current_group").val();
        var env = $("#current_env").val();
        var current_app = $("#current_app").val();
        if(current_app == undefined){
            current_app ='';
        }
        // var user_id = $(this).attr('data-id');
        swal({
            title: "确定要删除它吗?",
            text: "删除后将无法恢复，请谨慎！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            $.ajax({
                url: "/serviceinfo/delete/" + proj_id,
                type: "get",
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data["status"] == 200) {
                        window.location.href = linkss;
                    }
                }
            })
        });
    });
    $(".jenkinsoption").click(function () {
        console.log("del2323232");
        var linkss = $(".active a").attr("href");
        var app_id = $(this).attr("data-btn-id");
        $(this).remove("estiblish");
        console.log(123);
        $.ajax({
            url:"/serviceinfo/jenkins_del/",
            type:"post",
            data: {"app_id": app_id},
            success:function (data) {
                var data = JSON.parse(data);
                if (data["status"] == 200) {

                    // var tt = '<button class="btn btn-success" id="' + data["id"] + '">' + data["job_status"] + '</button>';
                    // $('[data-btn-id="' + data["id"] + '"]').remove();
                    // $('[data-td-id="' + data["id"] + '"]').append(tt);
                    swal({
                        title: "",
                        text: "Jenkins JOB删除成功"
                    }, function () {
                        // window.location.href = '/service/connservice_list/?env_type='+ +'&search_app='+ ;
                        window.location.href = linkss;
                    })
                } else if (data["status"] == 500) {
                    swal({
                        title: "",
                        text: "Jenkins JOB删除失败"
                    },function () {
                        // window.location.href = '/service/connservice_list/?env_type='+ +'&search_app='+ ;
                        window.location.href = linkss;
                    });
                    console.log("eeeeeeee");
                }
            }
        })
    })
    $(".estiblish").click(function () {
        var linkss = $(".active a").attr("href");
        var app_id = $(this).attr("data-btn-id");
        $(this).remove("estiblish");
        console.log(123);
        $.ajax({
            url: "/serviceinfo/jenkins/",
            type: "post",
            data: {"app_id": app_id},
            success: function (data) {
                var data = JSON.parse(data);
                if (data["code"] == 200) {

                    // var tt = '<button class="btn btn-success" id="' + data["id"] + '">' + data["job_status"] + '</button>';
                    // $('[data-btn-id="' + data["id"] + '"]').remove();
                    // $('[data-td-id="' + data["id"] + '"]').append(tt);
                    swal({
                        title: "",
                        text: "Jenkins JOB创建成功"
                    }, function () {
                        // window.location.href = '/service/connservice_list/?env_type='+ +'&search_app='+ ;
                        window.location.href = linkss;
                    })
                } else if (data["code"] == 500) {
                    swal({
                        title: "",
                        text: "Jenkins JOB创建失败"
                    },function () {
                        // window.location.href = '/service/connservice_list/?env_type='+ +'&search_app='+ ;
                        window.location.href = linkss;
                    });
                    console.log("eeeeeeee");
                }
            }
        })
    })
});